package com.dhnsoft.service.order;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhnsoft.mapper.orderMapper.OrderMapper;
import com.dhnsoft.po.Order;
import com.dhnsoft.po.Shopping;
import com.dhnsoft.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Date;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author 代浩楠
 * @since 2022-04-14
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {



    //生成订单的方法
    @Override
    public Order createOrders(Shopping commodity) {
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());//订单号
        order.setCommodityId(commodity.getId());//商品id
        order.setCommodityName(commodity.getCommodityName());//商品名称
        order.setCommodityImg(commodity.getCommodityImg());//商品封面
        order.setNickname("test");
        order.setTotalFee(new BigDecimal("0.01"));//课程价格
        order.setStatus(0);//0是未支付，1是已支付
        order.setPayType(1);//1是微信 2是支付宝
        order.setGmtCreate(new Date());
        baseMapper.insert(order);
        return order;
    }
}
